<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="js/vue.js"></script>
		<style type="text/css">
			.message {
				display: inline-block;
				width: 160px;
			}

			.success {
				background-color: lightgreen;
			}

			.msg-fail {
				background-color: pink;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<span>电话号码：</span>
			<input v-model="cellPhone" />
			<span class="message" :class="getClass">{{getMsg}}</span>
		</div>

		<script type="text/javascript">
			var vm = new Vue({
				el: "#app",
				data: {
					cellPhone: "13968290221",	
				},
				computed: {
					isOk() {
						var reg = /^1[3-9]\d{9}$/;
						return reg.test(this.cellPhone);
					},
					
					getClass(){
						return this.isOk?'success':'msg-fail';
					},
					
					getMsg(){
						return this.isOk?"手机号码格式正确":"手机号码格式错误";
					}
				},			
			})
		</script>
	</body>
</html>
